//
//  MLViewController.m
//  MsegmentBar
//
//  Created by DreamForStar on 04/22/2018.
//  Copyright (c) 2018 DreamForStar. All rights reserved.
//

#import "MLViewController.h"
#import "MLSegmentViewController.h"
#define random(r, g, b, a) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:(a)/255.0]
#define randomColor random(arc4random_uniform(256), arc4random_uniform(256), arc4random_uniform(256), arc4random_uniform(256))
@interface MLViewController ()
@property (nonatomic,strong) MLSegmentViewController *segmentVc;

@end

@implementation MLViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    [self test2];

}

- (void)test2{
    
    self.segmentVc.segmentBar.frame = CGRectMake(0, 0, self.view.width, 64);
    self.segmentVc.segmentBar.backgroundColor = [UIColor yellowColor];
    self.navigationItem.titleView =self.segmentVc.segmentBar;
    
    self.segmentVc.view.frame = self.view.bounds;
    [self.view addSubview:self.segmentVc.view];
    
    NSArray *items = @[@"周一",@"周二",@"周三"];
    
    UIViewController *vc1 = [[UIViewController alloc]init];
    vc1.view.backgroundColor = randomColor;
    
    UIViewController *vc2 = [[UIViewController alloc]init];
    vc2.view.backgroundColor = randomColor;
    
    UIViewController *vc3 = [[UIViewController alloc]init];
    vc3.view.backgroundColor = randomColor;
    
    [self.segmentVc setupBarWithItems:items childVcs:@[vc1,vc2,vc3]];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        
        
        NSArray *items = @[@"周一",@"周二",@"周三",@"周4",@"周5",@"周6",@"周一",@"周二",@"周三",@"周4",@"周5",@"周6"];
        
        NSMutableArray *vcArr = [NSMutableArray array];
        
        for (int i = 0; i < items.count; i++) {
            UIViewController *vc = [[UIViewController alloc]init];
            vc.view.backgroundColor = randomColor;
            [vcArr addObject:vc];
        }
        
        NSArray *array = [NSArray arrayWithArray:(NSArray *)vcArr];
        
        [self.segmentVc setupBarWithItems:items childVcs:array];
        
        [self.segmentVc.segmentBar updateWithConfig:^(MLSegmentBarConfig *config) {
            config.segmentBC([UIColor whiteColor]).itemNC([UIColor purpleColor]).itemSC([UIColor brownColor]).titleFS([UIFont systemFontOfSize:17]).indactorC([UIColor brownColor]).indHeight(2).indExtW(5);
        }];
        
    });
    
    
}
- (MLSegmentViewController *)segmentVc {
    if (!_segmentVc) {
        MLSegmentViewController *segmentVc = [[MLSegmentViewController alloc] init];
        [self addChildViewController:segmentVc];
        _segmentVc = segmentVc;
    }
    return _segmentVc;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
